<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
   
</head>

<body>

    <button id="copyButton">点击复制文本</button>
    <textarea id="copyTextarea">这里是要复制的内容</textarea>
    <script>
        document.getElementById('copyButton').addEventListener('click', function () {
            var copyTextarea = document.getElementById('copyTextarea');

            // 选中文本
            copyTextarea.focus();
            copyTextarea.select();

            // 复制文本
            try {
                var successful = document.execCommand('copy');
                var msg = successful ? '成功' : '失败';
                console.log('复制' + msg);
            } catch (err) {
                console.log('Oops, unable to copy');
            }
        });
    </script>
</body>

</html>